<template>
	<view class="waterfall-item-container">
		<view class="waterfall-item" @tap="onTap">
			<image :src="params.picture[0]" mode="widthFix" @load="emitHeight" @error="emitHeight"></image>
			<view class="content">
				<view class="title">{{params.title}}</view>
				<view class="bottom-tip">
					<view class="user-info">
						<image class="avatar" :src="params.avatar"></image>
						<view class="nickname">{{params.nickname|| '昵称'}}</view>
					</view>
					<view class="like">
						<image class="icon" src="@/components/waterfall/images/heart.png"></image>
						<text>{{params.likeCount}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "waterfallItem",
		options: {
			virtualHost: true
		},
		props: {
			params: {
				type: Object,
				default () {
					return {}
				}
			},
			tag: {
				type: String | Number,
				default: ''
			},
			index: {
				type: Number,
				default: -1
			}
		},
		data() {
			return {

			};
		},
		methods: {
			// 发出组件高度信息，在此处可以区分正确和错误的加载，给予错误的提示图片
			emitHeight(e) {
				const query = uni.createSelectorQuery().in(this);
				query.select('.waterfall-item-container').boundingClientRect(data => {
					let height = Math.floor(data.height);
					this.$emit("height", height, this.$props.tag);
				}).exec();
			},
			onTap() {
				this.$emit("click", this.$props.index, this.$props.tag);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.waterfall-item {
		// padding: 16rpx;
		background-color: #fff;
		border-radius: 8upx;
		font-size: 28rpx;
		color: #666;
		border-radius: 5px;
		overflow: hidden;

		image {
			display: block;
			width: 100%;
			// 默认设置一个图片的大约值
			height: 350rpx;
		}

		.content {
			padding: 20upx;

			.money {
				color: #fa3534;
				margin-top: 8rpx;
			}

			.label {
				background-color: #fa3534;
				color: #fff;
				font-size: 20rpx;
				padding: 4rpx 16rpx;
				border-radius: 20rpx;
			}

			.shop-name {
				font-size: 20rpx;
				color: #999;
			}

			.title {
				font-weight: bold;
				font-size: 30upx;
				color: black;

				display: -webkit-box;
				text-overflow: -o-ellipsis-lastline;
				text-overflow: ellipsis;
				line-clamp: 2;
				-webkit-line-clamp: 2; // 如果是3行改为3，以此类推
				-webkit-box-orient: vertical;
				overflow: hidden;
			}

			.bottom-tip {

				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 20upx;

				.user-info {
					display: flex;
					align-items: center;
					gap: 10upx;
					flex: 2;

					.avatar {
						width: 40upx;
						height: 40upx;
						border-radius: 100%;
					}

					.nickname {
						display: -webkit-box;
						text-overflow: -o-ellipsis-lastline;
						text-overflow: ellipsis;
						line-clamp: 1;
						-webkit-line-clamp: 1; // 如果是3行改为3，以此类推
						-webkit-box-orient: vertical;
						overflow: hidden;
					}
				}

				.like {
					flex: 1;
					display: flex;
					justify-content: end;
					align-items: center;
					gap: 20upx;

					image {
						width: 40upx;
						height: 40upx;
					}
				}
			}
		}
	}
</style>